package com.fifth.apartment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fifth.apartment.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.Set;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select * from user_role ur ,role ro where ro.id = ur.role_id and ur.user_id = #{id}")
    @Results({
            @Result(
                    id = true,column = "id",property = "id"
            ),
            @Result(
                    column ="id",
                    property = "permissions",
                    javaType = Set.class,
                    many = @Many(select = "com.fifth.apartment.mapper.PermissionMapper.queryPermissiomById")
            ),
            @Result(
                    column = "id",
                    property = "menus",
                    javaType = Set.class,
                    many = @Many(select = "com.fifth.apartment.mapper.MenuMapper.queryMenusById")
            )
    })
    Set<Role> queryRoleById(Integer id);
}
